package com.cmpe451.nutty.security;

import org.springframework.security.authentication.AnonymousAuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

import com.cmpe451.nutty.service.UserService;
import com.cmpe451.nutty.so.GuiUser;

@SuppressWarnings("deprecation")
public class CustomAnonymousAuthProvider extends AnonymousAuthenticationProvider {
	private UserService userDetailsService;

	@Override
	public Authentication authenticate(Authentication authentication) throws AuthenticationException {
		GuiUser user = userDetailsService.getGuestUser();

		UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(user, "pwd", user.getAuthorities());
		result.setDetails(user);

		return result;
	}

	@Override
	public boolean supports(Class<?> class1) {
		return true;
	}

	public void setUserDetailsService(UserService userDetailsService) {
		this.userDetailsService = userDetailsService;
	}
}
